package com.yc.exam.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.exam.entity.StudentGrade;
import com.yc.exam.entity.User;
import com.yc.exam.service.IStudentGradeService;
import com.yc.exam.service.IUserService;
import com.yc.exam.service.impl.StudentGradeServiceImpl;
import com.yc.exam.vo.StudentGradeVo;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * 前端控制器
 *
 * @author 王妍
 * @since 2022-03-23
 */
@RestController
@RequestMapping("/exam/studentGrade")
@AllArgsConstructor
public class StudentGradeController {

    private final IStudentGradeService  studentGradeService;
    private final IUserService userService;

    @GetMapping("page")
    public Page<StudentGradeVo> getGrades(Page<StudentGradeVo> studentGradeVoPage, Principal principal){
        final String userName = principal.getName();
        final User user = userService.loadUserByUserName(userName);
        return studentGradeService.pageVo(user.getId(),studentGradeVoPage);
    }

    @GetMapping("teacher/page")
    public Page<StudentGradeVo> getTeacherGrades(Page<StudentGradeVo> studentGradeVoPage, Principal principal){
        final String userName = principal.getName();
        final User user = userService.loadUserByUserName(userName);
        return studentGradeService.pageVo2(user.getId(),studentGradeVoPage);
    }

}
